import { Injectable } from "@angular/core";
import { _HttpClient } from "@delon/theme";
import { Observable } from "rxjs";
import { catchError, tap } from "rxjs/operators";
import { BaseService } from "../../core/service/base.service";

@Injectable({
  providedIn: 'root'
})
export class FileService extends BaseService {

  getUrl(): string {
    return "api/file";
  }

  viewPicture(id: string): Observable<any> {
    const url = `${this.getUrl()}/view-picture/${id}`;
    return this.http.get<any>(url).pipe(
      tap(_ => this.log(`fetched object id=${id}`)),
      catchError(this.handleError<any>(`getany id=${id}`)),
    );
  }

  download(id: string){
    const url = `${this.getUrl()}/download/${id}`;
    window.open(url, '_blank');
  }



  constructor(http: _HttpClient) {
    super(http);
  }
}
